home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / CPP / FI.ZIP / FILE_ITR.H < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-25  |  3.7 KB  |  135 lines

  1. #ifndef _file_itr_h_included
  2. #define _file_itr_h_included    // Prevent multiple includes
  3. //******************************************************************************
  4. //
  5. //                                  File Iterator
  6. //                                  (FILE_ITR.H)
  7. //
  8. //    PURPOSE:    Used to find all instances of a file specification, within
  9. //                a subdirectory tree. (e.g. Given the file spec,
  10. //                "h:\bcc\O*.HLP", the full path of all help files, that
  11. //                start with the letter 'O' are retrieved.)
  12. //
  13. //
  14. //      Date        Revision History
  15. //    --------    ------------------------------------------------------------
  16. //     4-30-95    Initial draft of FileIterator.
  17. //     5- 2-95    Added the operator, (long *), which returns the file's size.
  18. //
  19. //******************************************************************************
  20.  
  21. //------------------------------- HEADER FILES ---------------------------------
  22.  
  23. #include    <dir.h>            //  ffblk,
  24.                             //    MAXDIR, MAXDRIVE, MAXEXT, MAXFILE, MAXPATH
  25. #include    <stdlib.h>        //  size_t
  26. #include    <string.h>        //  strcpy()
  27. #include    <windows.h>        //  BOOL, TRUE
  28. #include    <_defs.h>        //  _CLASSTYPE()
  29.  
  30. #include    <arrays.h>        //  TArrayAsVector
  31.  
  32. //---------------------------- FORWARD DECLARATIONS ----------------------------
  33.  
  34. //--------------------------------- CONSTANTS ----------------------------------
  35.  
  36. char const NUL          = '\0';
  37. size_t const MaxFileLen = MAXFILE + MAXEXT;
  38. size_t const MaxPathLen = MAXDRIVE + MAXDIR;
  39.  
  40. //---------------------------- TYPE DECLARATIONS -------------------------------
  41.  
  42. //-------------------------- FUNCTION DECLARATIONS -----------------------------
  43.  
  44. //---------------------------- CLASS DECLARATIONS ------------------------------
  45. //
  46. //
  47.  
  48. class Subdir
  49. {
  50. public:
  51.     char    FachName[MaxPathLen];
  52.  
  53.     Subdir& operator= ( const Subdir& AsItem )
  54.     {
  55.         strcpy( FachName, AsItem.FachName );
  56.         return (*this);
  57.     }
  58.     int operator ==( const Subdir& AsItem ) const    {   return (0); }
  59.     int operator < ( const Subdir& AsItem ) const    {   return (0); }
  60. };
  61.  
  62. typedef TArrayAsVector<Subdir>    SubdirectoryTree;
  63.  
  64. class _CLASSTYPE FileIterator
  65. {
  66. public:
  67.  
  68.     //----------------------------------------------------------
  69.     //      Constructors.
  70.     //
  71.  
  72.     FileIterator( void );
  73.     FileIterator( const char *ApszFileSpec, BOOL AbRecurseSubdirs = TRUE );
  74.  
  75.  
  76.     //----------------------------------------------------------
  77.     //      Destructor.
  78.     //
  79.  
  80.     ~FileIterator( void );
  81.  
  82.  
  83.     //----------------------------------------------------------
  84.     //      An alternative method for setting the file-to-be-
  85.     //      searched-for specification.
  86.     //
  87.  
  88.     BOOL    SetFileSpec( const char *ApszFileSpec,
  89.                          BOOL AbRecurseSubdirs = TRUE );
  90.  
  91.  
  92.     //----------------------------------------------------------
  93.     //      Typical for() usuage:
  94.     //
  95.     //          char            *pszDataFile;
  96.     //          FileIterator    FileSearch( "*.dat" );
  97.     //
  98.     //          for (FileSearch.FirstFile();
  99.     //               FileSearch.MoreFiles();
  100.     //               FileSearch.NextFile())
  101.     //          {
  102.     //              pszDataFile = FileSearch;
  103.     //
  104.     //              //  process the data file
  105.     //          }
  106.     //
  107.  
  108.     void    FirstFile( void );
  109.     BOOL    MoreFiles( void ) const        {    return (FbMoreFiles);    }
  110.     void    NextFile( void );
  111.  
  112.     operator long() const;            //    File size
  113.     operator char *() const;        //    File name
  114.  
  115.  
  116. protected:
  117.  
  118.     unsigned            FuCurrentDir;
  119.     BOOL                FbMoreFiles;
  120.     ffblk                FfblkFileInfo;
  121.  
  122.  
  123. private:
  124.  
  125.     char                FachFileSpec[MaxFileLen];
  126.     char                FachFileName[MAXPATH];
  127.     SubdirectoryTree    *FpaDirectoryList;
  128.  
  129.     void    BuildSubdirectoryTree( const char *ApszFullSubdir );
  130.     void    FindNextSubdirectory( void );
  131. };
  132.  
  133. #endif
  134.  
  135.